﻿using System.Linq;

namespace StoCombatLogHUD.Parsing
{
	/// <summary>
	/// Usefull extensions for combatlog name entry.
	/// </summary>
	public static class CombatLogNameEntryExtensions
	{
		/// <summary>
		/// Determines whether [is player name] [the specified name entry].
		/// </summary>
		/// <param name="nameEntry">The name entry.</param>
		/// <returns>
		///   <c>true</c> if [is player name] [the specified name entry]; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsPlayerName(this CombatLogNameEntry nameEntry)
		{
			return nameEntry.InternalName.Contains("@");
		}

		/// <summary>
		/// Gets the actual name.
		/// </summary>
		/// <param name="nameEntry">The name entry.</param>
		/// <returns></returns>
		public static string GetActualName(this CombatLogNameEntry nameEntry)
		{
			return !nameEntry.IsPlayerName()
				       ? nameEntry.DisplayName
				       : nameEntry.InternalName.Split(' ').Skip(1).Aggregate(string.Empty, (name, part) => name + part).Split(']').First();
		}
	}
}
